<%--
  Created by IntelliJ IDEA.
  User: DongZhengWei
  Date: 2018/11/6
  Time: 10:45
  新增职权
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	String _id=request.getParameter("_");
%>

<form id="form_power_input" class="form-horizontal">
	<input type="hidden" name="keyId" id="keyId" value="${power.id}"/>

	<div class="form-group">
		<label class="col-md-2 control-label">序号</label>
		<div class="col-md-8">
			<input type="number" name="sortNo" id="sortNo" value="${power.sortNo}" class="form-control" placeholder="请输入序号">
		</div>
	</div>

	<div class="form-group">
		<label class="col-md-2 control-label">部门</label>
		<div class="col-md-8">
			<input disabled type="text" name="departmentName" id="departmentName" value="${department.name}" class="form-control">
			<input type="hidden" name="departmentId" id="departmentId" value="${department.id}" />
		</div>
	</div>

	<div class="form-group">
		<label class="col-md-2 control-label">岗位</label>
		<div class="col-md-8">
			<select name="postId" id="postId" class="selectpicker form-control" data-live-search="true" data-width="100%">
				<c:forEach var="item" items="${postList}" varStatus="status">
					<option value="${item.id}" <c:if test="${item.id == power.post.id}"> selected="selected"</c:if>>${item.name}</option>
				</c:forEach>
			</select>
		</div>
	</div>

	<div class="form-group">
		<label class="col-md-2 control-label">上级职权</label>
		<div class="col-md-8">
			<input type="text" name="parentId" id="parentId" class="form-control treepicker" title="请选择上级职权"/>
		</div>
	</div>

</form>

<script>

	$(function(){
	    fn_init_power_select();
        fn_power_input_validate();
	});

    $('#postId').selectpicker({
        style: 'btn-white',
        title : "请选择岗位"
    });


    //职权select tree菜单
    function fn_init_power_select(){
        $('#parentId').treepicker({
            style: 'btn-white'
        });

        var powerId = $('#keyId').val();
        var departmentId = $('#departmentId').val();
        __ajax_get("<%=path%>/main/power/tree_level", {powerId : powerId, departmentId : departmentId}, function(data){
			if(data.state == 1){
			    var list = data.data;
                $('#parentId').treepicker('setTreeNodes', list);

                var parentId = "${power.parent.id}";
                if(parentId){
                    $('#parentId').treepicker('val', parentId);
                }
			}
		})
	}

	//表单验证
	function fn_power_input_validate(){
        __init_bootstrapValidator("form_power_input", {
            postId : {
                validators : {
                    notEmpty : {
                        message : "请选择岗位"
					}
				}
			},
			sortNo : {
                validators : {
                    digits : {
                        message : "请输入整数"
					}
				}
			}
		});
	}

	//保存
	function fn_power_input_save(callback){
        if(!__is_validate("form_power_input")){
            return false;
		}

        __confirm_dialog(null, "确定提交么", function(){
            __form_save("form_power_input", "<%=path%>/main/power/save", function(data){
                callback(data.state==1 ? data.data : null);
			})
		});
	}


</script>